package ee.graphicscard.controller.graphicscardcontroller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import ee.graphicscard.controller.Command;
import ee.graphicscard.model.dao.GraphicsCardDAO;
import ee.graphicscard.model.dao.GraphicsCardDAOImpl;
import ee.graphicscard.model.dto.GraphicsCard;

public class GetAllGraphicsCardsCommand implements Command
{
	private Logger logger = Logger.getLogger(GetAllGraphicsCardsCommand.class);
	private int operationResult = 0;
	
	public int executeCommand(HttpServletRequest request,
			HttpServletResponse response) 
	{
		try
		{
			GraphicsCard[] arrayOfGraphicsCardsReceived = null;
			//There is no service layer implemented, so lets call GraphicsCardDAO directly
			GraphicsCardDAO graphicsCardDaoImpl = new GraphicsCardDAOImpl();
			arrayOfGraphicsCardsReceived = graphicsCardDaoImpl.findAll();
			request.setAttribute("arrayOfGraphicsCards", arrayOfGraphicsCardsReceived);
			operationResult = 1;
		}
		catch (Exception e)
		{
			logger.warn(e.getMessage());
			operationResult = 0;
			return operationResult;
		}
		
		return operationResult;
	}	
}
